interface BusinessService {
    doProcessing(): void;
}

class EJBService implements BusinessService {
    public doProcessing(): void {
        console.log("Processing task by invoking EJB Service");
    }
}

class JMSService implements BusinessService {
    public doProcessing(): void {
        console.log("Processing task by invoking JMS Service");
    }
}

class BusinessLookUp {
    public getBusinessService(serviceType: string): BusinessService {
        switch (serviceType.toUpperCase()) {
            case "EJB":
                return new EJBService();
            case "JMS":
                return new JMSService();
            default:
                throw new Error("Invalid service type");
        }
    }
}

class BusinessDelegate {
    private lookupService: BusinessLookUp = new BusinessLookUp();
    private businessService: BusinessService | null = null;
    private serviceType: string = '';
    public setServiceType(serviceType: string): void {
        this.serviceType = serviceType;
    }
    public doTask(): void {
        this.businessService = this.lookupService.getBusinessService(this.serviceType);
        this.businessService.doProcessing();
    }
}

class Client {
    businessService: BusinessDelegate;
    public constructor(businessService: BusinessDelegate) {
        this.businessService = businessService;
    }
    public doTask(): void {
        this.businessService.doTask();
    }
}

function main(): void {
    const businessDelegate: BusinessDelegate = new BusinessDelegate();
    businessDelegate.setServiceType("EJB");
    let client: Client = new Client(businessDelegate);
    client.doTask();
    businessDelegate.setServiceType("JMS");
    client.doTask();
}

main();
